﻿<UserControl xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
    xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL4" 
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" 
    xmlns:my="clr-namespace:FlowgraphViewer.Views" 
    xmlns:my1="clr-namespace:FlowgraphViewer.Model;assembly=FlowgraphViewer.Model" 
    xmlns:customPanels="clr-namespace:FlowgraphViewer.Panels"
    
    x:Name="userControl" x:Class="FlowgraphViewer.MainPage"
    
             mc:Ignorable="d"
             d:DesignWidth="640"
             d:DesignHeight="480" Loaded="userControl_Loaded">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Skins/MainSkin.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <CollectionViewSource x:Key="flowgraphViewSource" d:DesignSource="{d:DesignInstance my1:Flowgraph, CreateList=True}" />
            <CollectionViewSource x:Key="flowgraphNodesViewSource" Source="{Binding Nodes, Source={StaticResource flowgraphViewSource}}" />
        </ResourceDictionary>

    </UserControl.Resources>

    <UserControl.DataContext>
        <Binding Path="Main" Source="{StaticResource Locator}"/>
    </UserControl.DataContext>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="150"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid Background="#FF2F497C">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="25" />
                </Grid.ColumnDefinitions>
                <toolkit:Expander ExpandDirection="Left" Grid.Column="1">
                <Slider x:Name="sldZoom"  Maximum="{Binding MaxZoomLevel, Mode=TwoWay}" Minimum="{Binding MinZoomLevel, Mode=TwoWay}" Value="{Binding ZoomLevel, Mode=TwoWay}" LargeChange="0.25"/>
                </toolkit:Expander>
            </Grid>
        </Grid>
        
        <Canvas Background="White" x:Name="canvas" Grid.Column="1">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseLeftButtonDown">
                    <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding StartPanning}" PassEventArgsToCommand="True"/>
                </i:EventTrigger>
                <i:EventTrigger EventName="MouseLeftButtonUp">
                    <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding StopPanning}" PassEventArgsToCommand="True"/>
                </i:EventTrigger>
                <i:EventTrigger EventName="MouseMove">
                    <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding UpdatePanning}" PassEventArgsToCommand="True"/>
                </i:EventTrigger>
                <i:EventTrigger EventName="MouseWheel">
                    <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding ZoomCommand}" PassEventArgsToCommand="True"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <toolkit:ContextMenuService.ContextMenu>
                <toolkit:ContextMenu x:Name="cmnu">
                    <toolkit:MenuItem Header="Lawl" />
                </toolkit:ContextMenu>
            </toolkit:ContextMenuService.ContextMenu>

        </Canvas>
        <Canvas Grid.Column="1" Grid.RowSpan="3" x:Name="nodes" RenderTransformOrigin="0.5,0.5">
            <Canvas.RenderTransform>
                <CompositeTransform ScaleX="{Binding Value, ElementName=sldZoom, Mode=TwoWay}" ScaleY="{Binding Value, ElementName=sldZoom, Mode=TwoWay}"/>
            </Canvas.RenderTransform>
            <ItemsControl Background="Green" Canvas.Left="{Binding NodesX}" Canvas.Top="{Binding NodesY}" ItemsSource="{Binding Nodes}" ItemTemplate="{StaticResource FlowNodeDataTemplate}" Width="500" Height="500">
            </ItemsControl>
        </Canvas>
    </Grid>
</UserControl>
